<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号"
        width="160">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="联系电话"
        width="180">
      </el-table-column>
      <el-table-column
        prop="email"
        label="邮箱"
        width="220">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
    </el-table>

    <el-pagination
      align="right"
      background
      layout="prev, pager, next"
      :total="totals"
      :current-page="currentPage"
      :page-size="pageSize"
      @current-change="gotoPage"
      >
    </el-pagination>
  </div>

</template>

<script>

export default {
  name: 'myTable',
  data() {
    return {
      totals: 0,
      currentPage: 1,
      pageSize: 5,
      tableData: []
    }
  },
  methods: {
    gotoPage(curr) {
      this.currentPage = curr;
      this.userList();
    },
    userList() {
      // axios发送请求的格式
      this.$http.post("/user/list", {"currentPage": this.currentPage, "pageSize": this.pageSize})
        .then(result => {
          // 回调函数 当后端正确返回数据的时候走这里
          this.tableData = result.data.data;
          this.totals = result.data.totals;
        })
        .catch(result => {
          // 请求失败（请求不到后端）  比如404走这里
          alert("网络连接失败，请稍后重试！")
        })

    }
  },
  mounted() {
    this.userList();
  }
}
</script>

